<?php

if ($frmtGroup) {
    //debug($frmtGroup);
    ?>
    <div style="margin-bottom: 10px; text-transform: uppercase; ">
        <?php
        echo "<b><u>Debtors list for $group_name at $location_name</u></b>";
        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
        ?>
    </div>
    <div id="" class="list-table"
         style="border: 1px solid #B2B2B2; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;">
        <div class="apply-prompt"></div>
      <!--  <table width="100%">
            <thead style="background-color: #1C1C1C; font-size: 12px; font-family: Verdana,Arial,sans-serif; color: white;">
            <th width="13%" align="left">Registration Id</th>
            <th width="20%" align="left"> Property Name</th>
            <th width="20%" align="left">Owner</th>
            <th width="10%" align="left">Telephone</th>
            <th width="7%" align="left">Bill Year</th>
            <th width="10%" align="left"><?php /*echo 'Total Bill ' . CURRENCY; */?></th>
            <th width="10%" align="left"><?php /*echo 'Total Paid ' . CURRENCY; */?></th>
            <th width="10%" align="left"><?php /*echo 'Owing ' . CURRENCY; */?></th>
            </thead>
        </table>-->
        <div style="height: 400px; overflow: auto; margin-top: 10px;">
            <table id="debtors-table-data" class="list-table-data" width="100%" border="0">
                <thead style="background-color: #1C1C1C; font-size: 12px; font-family: Verdana,Arial,sans-serif; color: white;">
                <th width="13%" align="left">Registration Id</th>
                <th width="20%" align="left"> Property Name</th>
                <th width="20%" align="left">Owner</th>
                <th width="10%" align="left">Telephone</th>
                <th width="7%" align="left">Bill Year</th>
                <th width="10%" align="left"><?php echo 'Total Bill ' . CURRENCY; ?></th>
                <th width="10%" align="left"><?php echo 'Total Paid ' . CURRENCY; ?></th>
                <th width="10%" align="left"><?php echo 'Owing ' . CURRENCY; ?></th>
                </thead>
                <tbody>
                <?php
                $bill_tl = 0.00;
                $paid_tl = 0.00;
                $owe_tl = 0.00;
                foreach ($frmtGroup as $prp) {
                    $bill = 0.00;
                    if ($prp['Bill']) {
                        $bill = floatval($prp['Bill']['ttl_bill']);
                        $bill_tl = $bill_tl + $bill;
                    }
                    $paid = 0.00;
                    if ($prp['Bill']) {
                        $paid = floatval($prp['Bill']['ttl_payment']);
                        $paid_tl = $paid_tl + $paid;
                    }
                    $owe = 0.00;
                    if ($prp['Bill']) {
                        $owe = floatval($prp['Bill']['debit']);
                        $owe_tl = $owe_tl + $owe;
                    }
                    ?>
                    <tr>
                        <td width="13%" align="left">
                            <?php echo $prp['Property']['property_reg_no']; ?>
                        </td>
                        <td width="20%" align="left">
                            <?php echo $prp['Property']['name']; ?>
                        </td>
                        <td width="20%" align="left">
                            <?php echo $prp['Property']['owners_name']; ?>
                        </td>
                        <td width="10%" align="left">
                            <?php echo $prp['Property']['telephone']; ?>
                        </td>
                        <td width="7%" align="left">
                            <?php echo isset($prp['Bill']['year']) ? $prp['Bill']['year'] : ''; ?>
                        </td>
                        <td width="10%" align="left">
                            <?php
                            echo $bill;
                            ?>
                        </td>
                        <td width="10%" align="left">
                            <?php
                            echo $paid;
                            ?>
                        </td>
                        <td width="10%" align="left">
                            <?php
                            echo $owe;
                            ?>
                        </td>
                    </tr>
                <?php
                }
                ?>
                </tbody>
                <tfoot style="font-size: 12px; font-family: Verdana,Arial,sans-serif;">
                <th width="13%" align="left"></th>
                <th width="20%" align="left"></th>
                <th width="20%" align="left"></th>
                <th width="10%" align="left"></th>
                <th width="10%" align="left">Total</th>
                <th width="10%" align="left"><?php echo CURRENCY.' '.$bill_tl; ?></th>
                <th width="10%" align="left"><?php echo CURRENCY.' '.$paid_tl; ?></th>
                <th width="10%" align="left"><?php echo CURRENCY.' '.$owe_tl; ?></th>
                </tfoot>
            </table>
        </div>
        <!--<table width="100%">

        </table>-->
    </div>
<?php
} else {
    echo "No Report At the Moment.";
}

?>